#include <header.h>

int main(){

    char *port = "8080";
    char *ip = "192.168.106.130";

    int socket_fd = socket(AF_INET, SOCK_STREAM, 0);


    struct sockaddr_in sock;
    sock.sin_family = AF_INET;
    sock.sin_port = htons(atoi(port));
    sock.sin_addr.s_addr = inet_addr(ip);
    connect(socket_fd, (struct sockaddr *)&sock, sizeof(sock));


    // --------------------------------------------------
    int file_fd = open("1.txt", O_RDWR);

    while(1){
        char buf[2048]= {0};
        size_t ret = read(file_fd,buf, sizeof(buf));
        if(ret == 0){
            break;
        }


        send(socket_fd, &ret, sizeof(size_t), 0);
        send(socket_fd, buf, ret, 0);

    }
    
    // ------------------------------------------------

    close(file_fd);
    close(socket_fd);
    return 0;
}

